using System;
using System.IO;
using System.Xml;

namespace PacSnake
{
    /// <summary>
    /// The LevelSetInfo object is used to display the information about a
    /// level set like author, title, the number of levels in the set etc..
    /// For displaying this information, it's not necessary to load the levels
    /// themselves, so we do that in the LevelSet object, which is used when
    /// we're actually playing the game.
    /// </summary>
	public class LevelSetInfo
	{
        protected string title = string.Empty;
        protected string author = string.Empty;
        protected string url = string.Empty;
        protected string description = string.Empty;
        protected string email = string.Empty;
        protected string filename = string.Empty;

        protected int nrOfLevelsInSet = 0;
	    protected int lastFinishedLevelInSet = 0;

        
        /// <summary>
        /// Gets the information about the level set from the XML file
        /// </summary>
        /// <param name="levelSetFilename">Level set filename</param>
        public void LoadLevelSetInfo(string levelSetFilename)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(levelSetFilename);
            
            filename = levelSetFilename;
            title = doc.SelectSingleNode("//Title").InnerText;
            author = doc.SelectSingleNode("//Author").InnerText;
            description = doc.SelectSingleNode("//Description").InnerText;
            if (doc.SelectSingleNode("//Email") != null)
                email = doc.SelectSingleNode("//Email").InnerText;
            if (doc.SelectSingleNode("//Url") != null)
                url = doc.SelectSingleNode("//Url").InnerText;
                
            nrOfLevelsInSet = int.Parse(
                doc.SelectSingleNode("//NrOfLevelsInSet").InnerText);
            lastFinishedLevelInSet = int.Parse(
                doc.SelectSingleNode("//LastFinishedLevel").InnerText);
        }
        
        
        #region Properties
        
        public string Title
        {
            get { return title; }
        }
        
        public string Author
        {
            get { return author; }
        }
        
        public string Url
        {
            get { return url; }
        }
        
        public string Description
        {
            get { return description; }
        }
        
        public string Email
        {
            get { return email; }
        }
        
        public string Filename
        {
            get { return filename; }
        }
        
        public int NrOfLevelsInSet
        {
            get { return nrOfLevelsInSet; }
        }
        
        public int LastFinishedLevelInSet
        {
            get { return lastFinishedLevelInSet; }
        }
        
        #endregion
	}
}
